window.onload = function(){
   var btn1 =document.getElementById("btn1");//获取节点
   var ul1 = document.getElementById("ul1");//获取节点
// 删除
   var tableBg = document.getElementById("tableBg");
   var trS = tableBg.getElementsByTagName("tr");
   var del = tableBg.getElementsByClassName("del");
   var bought = document.getElementById("bought");
   console.log(bought);//检测节点是否被获取
	
	
	var num=0;//申明一个变量来记录点击的次数
	btn1.onclick =function(){//按钮的点击事件
		num++;//次数自身加1
		if(num%2==1){//判断点击的次数是奇数，就隐藏下面的内容
			ul1.style.display = "none";//内容隐藏
			btn1.style.background = "url(images/shopping_arrow_down.gif)";//更改背景
		}else{//否则偶数就显示内容
			ul1.style.display = "block";//显示内容
			btn1.style.background = "url(images/shopping_arrow_up.gif)";//更改背景
		}
		
	}
	
	//删除商品
	for(var i=0;i<del.length;i++){
	    del[i].onclick = function(){
	    	if(confirm("确定要删除这件商品吗？")){
	    		(this.parentElement.parentElement.parentElement).removeChild(this.parentElement.parentElement);
	    		}
		    }
	    del[del.length-1].onclick = function(){
	    	if(confirm("确定要清空购物车?")){
	    		(tableBg.parentElement).removeChild(tableBg);
	    		var div1 = document.createElement("div");
	    		bought.appendChild(div1);
	    		div1.style.width = "946px";
	    		div1.style.height = "326px";
	    	    div1.style.backgroundColor = "#ccc";
	    	    div1.innerHTML = "你还没有挑选商品,"
	    	    var a = document.createElement("a");
	    	    a.setAttribute("href","index.html");
	    		div1.appendChild(a);
	    	    a.innerHTML = "去挑选看看>>";
	    	    div1.style.textAlign = "center";
	    	    div1.style.lineHeight = "260px";
	    	    div1.style.fontSize = "18px";
	    	    a.style.fontSize = "18px";
	    	    a.style.color = "#2F74BA";
	    	}
	    }
	}
}//加载函数
